<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
    html, body{
        height: 100%; width: 100%; padding: 0;
    }
    body{
        background-image: url('/Public/game/ep06/clue01.png');background-position:  center;
        background-repeat:  no-repeat; background-size: 100% 100%;
    }
    #main, #clue {
        display: flex; flex-direction: column; align-items: center;justify-content: center; height: 100%; width: 100%;
    }
    #clue{
        background: url('/Public/game/ep06/clue_bg.png') center no-repeat; background-size: 100% 100%;  display: none;
        background-color: rgba(0, 0, 0, 0.8);
    }
    h1{
        display: flex; flex-direction: column; align-items: center;justify-content: center; height: 95%; width:60%; margin:auto;font-size: 2rem;font-family: '宋体';
    }
    a{
       margin-top: 10vh; width:30vh; height: 10vh;
    }
    a img{
        height: 100%; width: 100%;object-fit: contain;
    }
    a:active img{
        transform: scale(0.9);
    }
</style>
<body>
    <div id="main">
        <div id="clue">
            <h1 id="content"></h1>
        </div>
    </div>
    <audio id="audio" src="/Public/game/ep06/reward.MP3"></audio>
</body>
<script>
    const audio = document.getElementById('audio');
    let status = 'index'
    let clue = ''
    console.log(window.location.href);
    function getUrlParams(url) {
        const searchParams = new URLSearchParams(url.split('?')[1]);
        const params = {};
        for (const [key, value] of searchParams.entries()) {
            params[key] = value;
        }
        return params;
    }
    let params = getUrlParams(window.location.href);
    // $('a').attr('href','/Home/Trial/game?id=' + params.id)
    function getData(){
        $.ajax({
            url:'/Home/Trial/get_data?id=' + params.id,
            type:'get',
            success:function(res){
                let prevStatus = status
                status = res.data.status
                console.log(status);
                if(status == 'clue'){
                    if(prevStatus != 'clue'){
                        audio.play();
                    }
                    clue = res.data.clue.content
                    console.log(clue);
                }
                showContent(status)
                setTimeout(()=>{
                    getData()
                },1000)
            }
        })
    }
    getData()
    // setInterval(()=>{
    //     getData()
    //     console.log(status);
    //     showContent(status)
    // },1000)
    function showContent(status){
        let cluePanl = $('#clue')
        if(status == 'index'){
            cluePanl.hide()
            $('#content').text('')
            $('body').css('background-image', 'url(/Public/game/ep06/clue01.jpg)')
        }
        if(status == 'load'){
            cluePanl.hide()
            $('body').css('background-image', 'url(/Public/game/ep06/clue02.jpg)')
        }
        if(status == 'clue'){
            $('body').css('background-image', 'url(/Public/game/ep06/clue02.jpg)')
            cluePanl.show()
            $('#content').text(clue)

        }
        if(status == 'over'){
            cluePanl.hide()
            $('#content').text('')
            $('body').css('background-image', 'url(/Public/game/ep06/clue03.jpg)')
        }
    }
</script>
</html>